
import store from '@/store'
import { Notification } from 'element-ui'
import FiscalFeeDetail from "@/views/payfee/closeAccounts/fiscalFeeDetail"
import Vue from "vue";
const NFiscalFeeDetail = Vue.extend(FiscalFeeDetail);

function call(options) {
  let { key } = options.data
  switch (key) {
    case "CREATE_FEE_FORM":
      //结账一键创建费用单
     this.createFeeForm(options)
      break;
    case "SYS_NOTICE":
      this.sysNotice(options)
      break;
    case "MSG_RECALL":
      this.sysMsgRecall(options)
      break;
    default:
      this.defaultNotice(options)
      break;
  }

}

//默认通知  暂时没有逻辑处理
function defaultNotice(options){
  let { message} = options.data
  options.content = message
  this.openMessage(options)
}

//打开费用单明细
function createFeeForm(options){
  //结账一键创建费用单
  let { message} = options.data
  let { num } = JSON.parse(message)
  options.data.param = JSON.parse(message)
  options.content = `<div>账单生成条数[${num}],是否前往<span style="color: #3A71A8;">查看详情</span></div>`
  this.openMessage(options)
}

//系统通知
function sysNotice(options){
  let { message} = options.data
  let noticeMsg = JSON.parse(message)
  options.title = '你有一条新消息提醒'
  options.content = `<div>${noticeMsg.title}</div>`
  store.dispatch('ReadCount')
  this.openMessage(options)
}

//系统消息撤回
function sysMsgRecall(options){
  store.dispatch('ReadCount')
}


//费用明细表单
let seed = 1;
function openFiscalFeeDetail(param){
  const id = 'fiscalFeeDetail' + seed++;
  let instance = new NFiscalFeeDetail()
  instance.id = id;
  instance.$mount();
  document.body.appendChild(instance.$el);
  instance.dom = instance.$el;
  instance.show({batcheNo: param.batcheNo})
}



//打开消息提醒
function openMessage(options) {
  let params = {
    title: options.title,
    message: options.content,
    type: options.type||'success',
    duration: options.duration,
    // position: 'bottom-right',
    dangerouslyUseHTMLString: true,
    onClick() {
      let { key,param } = options
      switch (key) {
        case "CREATE_FEE_FORM":
          openFiscalFeeDetail(param)
          break;
        default:
          break;
      }
    }
  }
  Notification(params);
}

export default {
  call,
  openMessage,
  openFiscalFeeDetail,
  sysNotice,
  createFeeForm,
  defaultNotice,
  sysMsgRecall
};
